import 'package:flutter/material.dart';
import 'package:wanAndroid/common/http/base_model.dart';
import 'package:wanAndroid/common/http/http_service.dart';
import 'package:wanAndroid/common/http/http_uts.dart';
import 'package:wanAndroid/common/uts/log_uts.dart';
import 'package:wanAndroid/common/uts/sp_uts.dart';
import 'package:wanAndroid/common/uts/ui_uts.dart';
import 'package:wanAndroid/config/AppConfig.dart';
import 'package:wanAndroid/page/page_home.dart';

class PageSplash extends StatefulWidget {
  /// 启动页
  static Future<void> start(BuildContext context) async {
    return await Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => PageSplash()),
    );
  }

  @override
  State<StatefulWidget> createState() => _PageSplash();
}

class _PageSplash extends State<PageSplash> {
  @override
  void initState() {
    ///定时器

    HttpService.userInfo(HttpCallback((rsp) {
      Future.delayed(
        Duration(seconds: 1),
      ).then((value) {
        PageHome.startAndRemove(context);
      });
      BaseModel baseModel = BaseModel.fromJson(rsp.data);
      var baseModel2 = baseModel;
      LogUts.showLog("${baseModel.errorCode}  = ${baseModel2.errorMsg}",
          tag: "【检测登录】");
      SPUts.setBoolean(AppConfig.KEY_IS_LOGIN, -1000 != baseModel.errorCode);
    }, (err) {
      SPUts.setBoolean(AppConfig.KEY_IS_LOGIN, false);
    }));
    super.initState();
  }

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: UiUts.NoTitlebar(),
        body: Center(
          child: Text("启动页···"),
        ),
      );
}
